<!--
 * @FileDescription 诊断仪
 * @Author lz
 * @Date 20230612 15:21:31
 * @LastEditors lz
 * @LastEditTime 20230612 15:21:31
-->
<template>
  <div class="Dia_wp">
    <div class="Popup">
      <div class="titBox">
        诊断仪
        <span class="txt">读取故障码</span>
        <close-outlined class="cancel" @click="cancel" />
        <img
          src="/public/images/诊断仪-diagnostic-apparatus/返回.png"
          class="return"
          @click="returnKey"
        />
      </div>
      <div class="pop_cont">
        <div class="tit_list">
          <div class="t1">系统</div>
          <div class="t2">故障码</div>
          <div class="t3">故障描述</div>
        </div>
        <div class="listBox">
          <div
            class="pop_list"
            v-for="(item, index) in HomeContent.Default.DefaultCodeData.value"
            :key="index"
          >
            <div class="t1 BN">
              {{ item[0] }}
            </div>
            <div class="t2 BN">
              {{ item[1] }}
            </div>
            <div class="t3 BN">
              {{ item[2] }}
            </div>
          </div>
        </div>
      </div>
      <div class="footer">
        <div class="cleanUp" @click="clearCode">
          <img src="/images/ic_clearcode.png" class="btn_ico" />
          清除故障码
        </div>
        <div class="read" @click="readCode">
          <img src="/images/ic_readcode.png" class="btn_ico" />
          读取故障码
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { CloseOutlined } from "@ant-design/icons-vue";
import { ClientMessage } from "../../../../runtime/generate/message/ClientMessage";
import WebSocketComponent from "../../../../runtime/module/WebSocket/WebSocketComponent";
import { onMounted, reactive, ref } from "vue";
import HomeContent from "../HomeContent";
import MessageCode from "../MessageCode";
const state = reactive({
  tabList: <any>[],
});
const props = defineProps({
  codeData: [],
});
// 关闭
function cancel() {
  WebSocketComponent.Default.PostMessage(
    new ClientMessage.DiagnosisAdapterMessage(
      MessageCode.Default.MsgCodesList.DIAGNOSTIC_DECODER_CLOSE
    )
  );
  HomeContent.Default.DiagnosShow.value = false;
  HomeContent.Default.DataFlow.value = false;
  HomeContent.Default.ReadDefaultCode.value = false;
}
// 返回
function returnKey() {
  HomeContent.Default.ReadDefaultCode.value = false;
  HomeContent.Default.DiagnosShow.value = true;
}
//读取
async function readCode() {
  HomeContent.Default.DefaultCodeData.value = [];
  let newArr: any = await WebSocketComponent.Default.PostMessageAsync(
    new ClientMessage.DiagnosisAdapterRequest(
      MessageCode.Default.MsgCodesList.DIAGNOSTIC_DECODER_READ_FAULT_CODE
    )
  );
  console.log("读取++++++++++++++++++++++++++++", JSON.parse(newArr.Content).Result);
  state.tabList = JSON.parse(newArr.Content).Result;
  for (let i = 0; i < state.tabList.length; i++) {
    task(i);
  }
}
function task(i: any) {
  setTimeout(function () {
    let newData = state.tabList[i].split(":");
    HomeContent.Default.DefaultCodeData.value.push(newData);
  }, 500 * i);
}
//清除
async function clearCode() {
  HomeContent.Default.DefaultCodeData.value = [];
  let newArr: any = await WebSocketComponent.Default.PostMessageAsync(
    new ClientMessage.DiagnosisAdapterRequest(
      MessageCode.Default.MsgCodesList.DIAGNOSTIC_DECODER_CLEAR_FAULT_CODE
    )
  );
  console.log("清除----------------------", JSON.parse(newArr.Content).Result);
  state.tabList = JSON.parse(newArr.Content).Result;
}
onMounted(async () => {});
</script>

<style scoped>
.Dia_wp {
  width: 100%;
  height: 100%;
  background-color: rgb(0, 0, 0, 0.1);
  position: relative;
}

.Popup {
  width: 1220px;
  height: 660px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -60%);
  background: #ffffff;
  border-radius: 16px 16px 16px 16px;
}

.titBox {
  height: 54px;
  font-size: 36px;
  font-weight: 600;
  color: #000000;
  line-height: 42px;
  margin-top: 30px;
  margin-left: 40px;
}
.txt {
  color: #000000;
  font-size: 28px;
  font-weight: 600;
  margin-left: 14px;
}
.cancel {
  font-size: 28px;
  font-weight: 600;
  float: right;
  margin-top: 4px;
  margin-right: 30px;
}
.return {
  position: absolute;
  right: 76px;
}
.pop_cont {
  width: 100%;
  height: 500px;
}

.tit_list {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  text-align: center;
  height: 44px;
  line-height: 42px;
  margin-left: 40px;
}

.pop_list {
  font-size: 16px;
  font-weight: 400;
  color: #1a1a1a;
  height: 53px;
  text-align: center;
  line-height: 52px;
  overflow: hidden;
  margin-left: 40px;
}

.t1 {
  width: 312px;
  float: left;
  background: #f7f8fb;
  border: 1px solid #ede8f4;
  border-radius: 10px 0 0 0;
}

.t2 {
  width: 208px;
  float: left;
  background: #f7f8fb;
  border-top: 1px solid #ede8f4;
  border-bottom: 1px solid #ede8f4;
}

.t3 {
  width: 620px;
  height: 100%;
  float: left;
  background: #f7f8fb;
  border: 1px solid #ede8f4;
  border-radius: 0 10px 0 0;
}

.listBox {
  width: 98.5%;
  overflow-y: auto;
  height: 450px;
}

.listBox::-webkit-scrollbar {
  width: 6px;
  height: 1px;
}

.listBox::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: #dfe1e8;
}

.listBox::-webkit-scrollbar-track {
  border-radius: 10px;
  background: #f8f8f8;
}

.BN {
  background: none;
  border-radius: 0;
  border-bottom: 1px solid #ede8f4;
  border-top: none;
}

.footer {
  height: 78px;
  width: 100%;
  margin-top: -6px;
  border-top: 1px solid #ede8f4;
  position: relative;
}

.cleanUp {
  width: 156px;
  height: 48px;
  line-height: 46px;
  font-size: 16px;
  font-weight: 500;
  color: #202020;
  background: #ffffff;
  border-radius: 6px 6px 6px 6px;
  opacity: 1;
  border: 1px solid #e9e9e9;
  position: absolute;
  bottom: 12px;
  left: 440px;
}

.read {
  width: 156px;
  height: 48px;
  line-height: 46px;
  font-size: 16px;
  font-weight: 500;
  color: #202020;
  background: #9bfb4e;
  border-radius: 6px 6px 6px 6px;
  opacity: 1;
  position: absolute;
  right: 440px;
  bottom: 12px;
}
.getFlow {
  width: 156px;
  height: 48px;
  line-height: 46px;
  font-size: 16px;
  font-weight: 500;
  color: #202020;
  background: pink;
  border-radius: 6px 6px 6px 6px;
  opacity: 1;
  position: absolute;
  right: 0px;
  bottom: 12px;
}
.btn_ico {
  width: 24px;
  margin-top: -4px;
  margin-left: 20px;
}
</style>
